using System;
using System.Data.Entity;
using System.Data.SQLite;
using System.Windows.Forms;
using StudentManagementSystem;

namespace StudentManagementSystem
{
    public partial class Form1 : Form
    {
        private SchoolManager manager = new SchoolManager();
        private Database db = new Database();

        public Form1()
        {
            InitializeComponent();
            db.CreateDatabase();
        }

        private void buttonAddSchool_Click(object sender, EventArgs e)
        {
            string schoolName = textBoxSchoolName.Text;
            manager.AddSchool(schoolName);
            manager.LogOperation($"Added school: {schoolName}");
            UpdateLogsListBox();
        }

        private void buttonAddClass_Click(object sender, EventArgs e)
        {
            string className = textBoxClassName.Text;
            int schoolId = int.Parse(textBoxSchoolId.Text);
            manager.AddClass(className, schoolId);
            manager.LogOperation($"Added class: {className} to school {schoolId}");
            UpdateLogsListBox();
        }

        private void buttonAddStudent_Click(object sender, EventArgs e)
        {
            string studentName = textBoxStudentName.Text;
            int classId = int.Parse(textBoxClassId.Text);
            manager.AddStudent(studentName, classId);
            manager.LogOperation($"Added student: {studentName} to class {classId}");
            UpdateLogsListBox();
        }

        private void UpdateLogsListBox()
        {
            listBoxLogs.Items.Clear();
            manager.ShowLogs();
        }
    }
}